{extend name="table"}
{block name="button"}
<!--{if auth("add")}-->
<button class='layui-btn layui-btn-sm layui-btn-primary' data-modal='{:url("add")}?cat_id={$cat_id}' data-title="创建仓库信息">添加仓库</button>
<!--{/if}-->
<!--{if auth("remove")}-->
<button data-table-id="WarehousTable" data-action='{:url("remove")}' data-rule="id#{id}" data-confirm="确定要删除选中的仓库吗？" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除</button>
<!--{/if}-->
{/block}
{block name="content"}
<div class="think-box-shadow">
    <table id="WarehousTable" data-url="{:sysuri()}?cat_id={$cat_id}" data-target-search="form.form-search"></table>
</div>
<script>
    $(function () {
        $('#WarehousTable').layTable({
            even: true, height: 'full', page: false,
            sort: {field: 'sort desc,id', type: 'asc'},
            cols: [[
                {checkbox: true, field: 'sps', fixed: 'left'},
                {field: 'sort', title: '排序权重', width: 100, align: 'center', sort: true, templet: '#SortWarehouseTpl'},
                {
                    field: 'name', title: '仓库名称', width: '8%', align: 'center', templet: function (d) {
                        return layui.laytpl('{{d.name}}').render(d);
                    }
                },
                {
                    field: 'desc', title: '仓库地址', width: '27%', templet: function (d) {
                        return layui.laytpl('{{d.address}}').render(d);
                    }
                },
                {
                    field: 'desc', title: '仓库简介', width: '26%', templet: function (d) {
                        return layui.laytpl('{{d.desc}}').render(d);
                    }
                },
                {field: 'status', title: '状态', width: 120, align: 'center', templet: '#StatusWarehouseTpl'},
                {toolbar: '#warehousetoolbar', title: '操作面板', width: 207, align: 'center', fixed: 'right'},
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusWarehouseTpl)', function (object) {
            object.data = {status: object.elem.checked > 0 ? 1 : 0};
            object.data.id = object.value.split('|')[object.data.status] || object.value;
            $.form.load("{:url('state')}", object.data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#WarehousTable').trigger('reload');
                }); else {
                    $('#WarehousTable').trigger('reload');
                }
                return false;
            }, false);
        });
    })
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusWarehouseTpl">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusWarehouseTpl" {{-d.status>0?'checked':''}}>
    <!--{else}-->
    {{-d.status ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
    <!--{/if}-->
</script>
<!-- 列表排序权重模板 -->
<script type="text/html" id="SortWarehouseTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>
<!-- 操控面板的模板 -->
<script type="text/html" id="warehousetoolbar">
    <!--{if auth("report")}-->
    <a data-modal='{:url("report")}?id={{d.id}}' data-width="90%" data-title="仓库报单登记" class='layui-btn layui-btn-sm layui-btn-normal'>报 单</a>
    <!--{/if}-->
    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-sm" data-title="编辑仓库信息" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <!--{/if}-->
    <!--{if auth('remove')}-->
    <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除此仓库吗？" data-action="{:url('remove')}" data-value="id#{{d.id}}">删 除</a>
    <!--{/if}-->
</script>
{/block}